package collection;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Map
 */
public class MapExercise {

    public static void main(String[] args) {
        /*
            使用HashMap添加3个员工对象
            键：员工id
            值：员工对象
            遍历显示工资>18000的员工(遍历方式至少两种)
            员工类：姓名、工资、员工id
         */
        Yg aa = new Yg("aa", 10000.0, "123");
        Yg bb = new Yg("bb", 20000.0, "456");
        Yg cc = new Yg("cc", 30000.0, "789");
        Map hashMap = new HashMap<>();
        hashMap.put(aa.getId(), aa);
        hashMap.put(bb.getId(), bb);
        hashMap.put(cc.getId(), cc);

        System.out.println("第一种遍历方式：获取keySet");
        Set keySet = hashMap.keySet();
        for (Object key : keySet) {
            Yg yg = (Yg)(hashMap.get(key));
            if (yg.getPrice() >= 18000.0) {
                System.out.println(key + ":" + yg);
            }
        }

        System.out.println("第二种遍历方式：获取entrySet");
        Set entrySet = hashMap.entrySet();
        for (Object entry : entrySet) {
            Map.Entry e = (Map.Entry) entry;
            Yg yg = (Yg)e.getValue();
            if (yg.getPrice() >= 18000.0) {
                System.out.println(e.getKey() + ":" + yg);
            }
        }

    }
}

class Yg {

    private String name;

    private double price;

    private String id;

    public Yg(String name, double price, String id) {
        this.name = name;
        this.price = price;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Yg{" +
                "name='" + name + '\'' +
                ", price=" + price +
                ", id='" + id + '\'' +
                '}';
    }
}